{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3770cdb9-5263-4c5a-9792-b439034a8fb7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入半径： 2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "圆面积=12.56\n",
      "球体体积=33.49\n"
     ]
    }
   ],
   "source": [
    "#圆面积、球体积\n",
    "import math\n",
    "PI = 3.14    #定义变量\n",
    "def area(r): #定义函数\n",
    "    return PI*r*r  #圆面积\n",
    "def volume(r):\n",
    "    return 4*PI*pow(r,3)/3  #球体体积\n",
    "def main():\n",
    "    r = float(input(\"请输入半径：\"))#输入半径并转换为浮点数\n",
    "    print('圆面积={0:2.2f}'.format(area(r)))\n",
    "    print('球体体积={0:2.2f}'.format(volume(r)))\n",
    "if __name__ == '__main__': #如果独立运行时，则运行测试代码\n",
    "    main()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac507530-2816-4240-bc5c-053bffdc3a81",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
